﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section styles{
    <style>

        #channel-tree {
            width: 100% !important;
            height: -webkit-calc(100vh - 87px);
            height: -moz-calc(100vh - 87px);
            height: calc(100vh - 87px);
        }
        #newcategory-detail {
            width: 100% !important;
            height: -webkit-calc(100vh - 86px);
            height: -moz-calc(100vh - 86px);
            height: calc(100vh - 86px);
            overflow: auto;
            padding-right: 5px;
        }
        .bottom {
            width: 100%;
            position: absolute;
            bottom: 0px;
            left: 0px;
            height: 50px;
            line-height: 50px;
            border-top: 1px solid #eee;
            background-color: #fff;
        }

        .layout-content {
            padding: 0px 8px;
            text-align: left;
        }
        #channel-tree-empty{
             text-align:center;
        }
    </style>
}

<div class="layui-row layui-col-space15">
    <div class="layui-col-md5">
        <div class="layui-card">
            <div class="layui-card-header">
                <div class="layui-row" style="margin-bottom:15px;">
                    <label class="layui-form-label">从栏目</label>
                    <div class="layui-input-inline">
                        <input type="text" name="channelname" placeholder="请输入栏目名称" class="layui-input">
                    </div>
                    <button type="button" class="pear-btn pear-btn-md pear-btn-primary" id="btn_TreeFuzzySearch">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                </div>
            </div>
            <div class="layui-card-body">
                <div style="overflow: auto" class="divscrollbar">
                    <ul id="channel-tree-empty" class="layui-hide">没有匹配数据</ul>
                    <ul id="channel-tree" class="dtree" data-id="0"></ul>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-col-md7">
        <div class="layui-card">
            <div class="layui-card-header">复制到</div>
            <div class="layui-card-body">
                <div id="newcategory-detail" class="divscrollbar">
                    <form class="layui-form " style="padding: 15px 0 0 0;">
                        <div class="layui-form-item">
                            <label class="layui-form-label">复制到栏目</label>
                            <div class="layui-input-block">
                                <input id="channelcascader" name="TargetChannelId"/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">复制类型</label>
                            <div class="layui-input-block">
                               <select name="TranslateType">
                                   <option value="0">仅转移内容</option>
                                   <option value="1">仅转移栏目</option>
                                   <option value="2">转移栏目及内容</option>
                               </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">复制后删除</label>
                            <div class="layui-input-block">
                                <input type="checkbox" name="IsDeleteAfterTranslate" value="1" title="删除">
                            </div>
                        </div>
                        <div class="bottom">
                            <div class="button-container">
                                <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="translate-submit" id="translate-submit">确定</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>


@section scripts{
    <script>
                layui.use([ 'form', 'lscom' , 'dtree', 'layCascader'], function () {
                    let dtree = layui.dtree;
                    let form = layui.form;
                    let $ = layui.jquery;
                    let lscom = layui.lscom;
                    var layCascader = layui.layCascader;
                    let MODULE_PATH = "/Cms/Channel/";
                    let parentId = 0;

                    let TreeFuzzySearch= dtree.render({
                        elem: "#channel-tree",
                        initLevel: "10",
                        line: true,
                        ficon: ["1", "-1"],
                        icon: ["0", "4"],
                        method: 'get',
                        url: MODULE_PATH + "GetChannelDtree",
                        response: {
                            message: "msg",
                            statusCode: 0,
                        },
                        none: "没有数据",
                        dataStyle: "layuiStyle",
                        dataFormat: "list",
                        checkbar: true,
                        checkbarType: "self", // 默认就是all，其他的值为： no-all  p-casc   self  only
                        done: function (res, $ul, first) {
                       }
                    });

                    dtree.on("node(channel-tree)", function (obj) {
                     
                        parentId = obj.param.nodeId;
                    });

                    $("#btn_TreeFuzzySearch").click(function () {
                        var input = $("input[name='channelname']").val();
                        // 调用内置函数搜索节点
                        TreeFuzzySearch.fuzzySearch(input);
                        if ($("#channel-tree>li").hasClass('layui-hide') ) {
                            $("#channel-tree-empty").removeClass("layui-hide");
                        } else {
                            $("#channel-tree-empty").addClass("layui-hide");
                        }
                    });

                     lscom.ajax({
                            url: "/Cms/Channel/GetChannleCascader?channelId=0",
                            type:'GET',
                            lsHandleError: false
                        }).done(function(data) {
                            if (data.code == 0) {
                                layCascader({
                                    elem: '#channelcascader',
                                    options: data.data,
                                    clearable: true
                                });
                            }
                        }).fail(function(message) {
                            lscom.notify.error(message);
                        })

                        form.on('submit(translate-submit)', function (data) {
                                        
                                        var params = dtree.getCheckbarNodesParam("channel-tree");
                                        console.log(JSON.stringify(params));
                                        var channelids =[];
                                        $.each(params,function(k,v){
                                          channelids.push(v.nodeId);
                                        });
                                        if(channelids.length==0){
                                            parent.layer.msg("请选择栏目", {
                                                icon: 3,
                                                time: 1000
                                            });
                                        }
                                        
                                        data.field.ChannelIds=channelids;
                                        if(data.field.TargetChannelId==""){
                                             parent.layer.msg("请选择复制到栏目", {
                                                icon: 3,
                                                time: 1000
                                            });
                                        }

                                        var field = data.field;
                                        var waitIndex = parent.layer.load(2);
                                        lscom.ajax({
                                            url: "/Cms/Channel/SetTranslate",
                                            data: JSON.stringify(field),
                                            lsHandleError: false
                                        }).done(function (data) {
                                            if (data.code == 0) {
                                               setTimeout(function(){
                                                        var  muilttab = localStorage.getItem("muilt-tab");
                                                        if (muilttab=="true") {
                                                        parent.layer.close(waitIndex);
                                                        parent.layui.admin.closeCurrentTab();
                                                    }
                                                    parent.layui.admin.jump(10012,"栏目管理",'/Cms/Channel/Index');
                                                },1000); 
                                            }
                                        }).fail(function (message) {
                                            lscom.notify.error(message);
                                        }).always(function () {
                                            parent.layer.close(waitIndex);
                                        });
                                        return false;
                                    });


                });
    </script>
}
